/**
 * 第三方接口服务
 */
import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { ApiConfigList, ApiConfigListPageParam } from './model';

/**
 * 列表
 */
export async function page(params?: ApiConfigListPageParam) {
  const res = await request.post<ApiResult<PageResult<ApiConfigList>>>(
    '/apiConfigList/page',
    params
  );
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 新增
 */
export async function add(data: ApiConfigList) {
  const res = await request.post<ApiResult<any>>('/apiConfigList/add', data);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新
 */
export async function update(data: ApiConfigList) {
  const res = await request.post<ApiResult<any>>('/apiConfigList/update', data);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除
 */
export async function remove(id?: number | string) {
  const res = await request.post<ApiResult<any>>('/apiConfigList/delete', {
    id
  });
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新状态
 */
export async function changeStatus(data: ApiConfigList) {
  const res = await request.post<ApiResult<any>>(
    '/apiConfigList/changeStatus',
    data
  );
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新账套
 */
export async function changeIsMaster(data: ApiConfigList) {
  const res = await request.post<ApiResult<any>>(
    '/apiConfigList/changeIsMaster',
    data
  );
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新外部接口是否提交状态
 */
export async function changeIsSubmit(data: ApiConfigList) {
  const res = await request.post<ApiResult<any>>(
    '/apiConfigList/changeIsSubmit',
    data
  );
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新外部接口是否审核状态
 */
export async function changeIsAudit(data: ApiConfigList) {
  const res = await request.post<ApiResult<any>>(
    '/apiConfigList/changeIsAudit',
    data
  );
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
